function isEmpty(value){
    if(typeof(value)=='undefined'|| value == null || value=='null' || value ==''){
        return true;
    }else{
        return false;
    }
}
/**
 *
 * @param tableId
 * @param sAjaxSource ajaxURL
 * @param aoColumns   列说明
 * @param aoColumnDefs 列处理
 * @param parm 参数对象
 * @param func 点击行事件
 * @returns
 */
function initTable(tableId,sAjaxSource,isSort,aoColumns,aoColumnDefs,parm,func,rowFunc,isScroll){
    var flag = isScroll;
    if(!isScroll){
        flag = false;
    }
    var sTable = $("#"+tableId).dataTable({
        "oLanguage" : { // 汉化
            "sProcessing" : "正在加载数据...",
            "sLengthMenu" : "显示_MENU_条 ",
            "sZeroRecords" : "没有您要搜索的内容",
            "sInfo" : "从_START_ 到 _END_ 条记录       共计 _TOTAL_ 条",
            "sInfoEmpty" : "记录数为0",
            "sInfoFiltered" : "(全部记录数 _MAX_条)",
            "sInfoPostFix" : "",
            "sSearch" : "搜索",
            "sUrl" : "",
            "oPaginate" : {
                "sFirst" : "第一页",
                "sPrevious" : " 上一页 ",
                "sNext" : " 下一页 ",
                "sLast" : " 最后一页 "
            }
        },
        "bJQueryUI": true,
        "bPaginate" : true,// 分页按钮
        "bFilter" : false,// 搜索栏
        "bLengthChange" : true,// 每行显示记录数
        "iDisplayLength" : 10,// 每页显示行数
        "bSort" : isSort,// 排序
        //"aLengthMenu": [[50,100,500,1000,10000], [50,100,500,1000,10000]],//定义每页显示数据数量
        //"iScrollLoadGap":400,//用于指定当DataTable设置为滚动时，最多可以一屏显示多少条数据
        //"aaSorting": [[4, "desc"]],
        "bInfo" : true,// Showing 1 to 10 of 23 entries 总记录数没也显示多少等信息
        "bWidth":true,
        "scrollX":flag,
        "bStateSave":false,
        //"sScrollY": "62%",
        //"sScrollX": "210%",
        "bScrollCollapse": true,
        "sPaginationType" : "full_numbers", // 分页，一共两种样式 另一种为two_button   // 是datatables默认
        "bProcessing" : true,
        "bServerSide" : true,
        "bDestroy": true,
        "bSortCellsTop": false,
        "sAjaxSource":sAjaxSource,
        "aoColumns":aoColumns,
        "aoColumnDefs":aoColumnDefs,
        "fnServerData" :
            function(sSource, aoData, fnCallback) {
                if(isEmpty(parm)){
                    parm = new Object();
                }
                parm.aoData = JSON.stringify(aoData);
                $.ajax({
                    "type" : 'post',
                    "url" : sSource,
                    "dataType" : "json",
                    "async" : false,
                    "data" : parm ,
                    "success" : function(resp) {
                        var data = resp.aoData;
                        fnCallback(resp);
                        var funds = $("#fundssource").val();
                        if(funds != 'undefined' ){
                            $("#areacapitalnum").text(resp.areacapitalnum);
                            $("#citycapitalnum").text(resp.citycapitalnum);
                            $("#areacitynum").text(resp.areacitynum);
                            $("#independentnum").text(resp.independentnum);
                            $("#othernum").text(resp.othernum);
                            $("#count").text(resp.count);
                        }
                    }
                });
            }
        ,
        "sDom":'<"top"f<"clear">>rt<"row"<"col-xs-2"l><"col-xs-3"i><"col-xs-7"p><"clear">>',
        "fnDrawCallback": function( oSettings ) {
            clickTable(tableId,func,oSettings.aoColumns,this);
        },
        "fnRowCallback":function(nRow, aData, iDisplayIndex) {
            if(rowFunc != null){
                rowFunc(nRow, aData, iDisplayIndex);
            }
        }
    });
    return sTable;
}

function clickTable(id,func,columns,datatable){
    $("#"+id+" tr td").click(function(){
        var index = $(this).index();
        var iPos = datatable.fnGetPosition( this );
        var aData = datatable.fnGetData( iPos );
        var buttonCols = new Array();
        $.each(columns, function(i, item) {
            if(item.show == "button"){
                buttonCols.push(i);
            }
        });
        var flag = true;
        $.each(buttonCols, function(i, item) {
            if(index+1 == item){
                flag = false;
            }
        });
        if(flag){
            func(aData);
        }
    });
}